﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="IcDiscoProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class IcDiscoProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.IcDisco, BesAsm.MasterData.Entities.IcDiscoKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.IcDiscoKey key)
		{
			return Delete(transactionManager, key.IcDiscoId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_icDiscoId">Primary key, IC Disco ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _icDiscoId)
		{
			return Delete(null, _icDiscoId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_icDiscoId">Primary key, IC Disco ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _icDiscoId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_ASSUMPTION_CODES key.
		///		FK_IC_DISCOS_ASSUMPTION_CODES Description: 
		/// </summary>
		/// <param name="_assumptionCode">A code indicating the type of assumption resulting in the Disco record; foreign key to ASSUMPTION_CODES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByAssumptionCode(System.String _assumptionCode)
		{
			int count = -1;
			return GetByAssumptionCode(_assumptionCode, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_ASSUMPTION_CODES key.
		///		FK_IC_DISCOS_ASSUMPTION_CODES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_assumptionCode">A code indicating the type of assumption resulting in the Disco record; foreign key to ASSUMPTION_CODES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		/// <remarks></remarks>
		public TList<IcDisco> GetByAssumptionCode(TransactionManager transactionManager, System.String _assumptionCode)
		{
			int count = -1;
			return GetByAssumptionCode(transactionManager, _assumptionCode, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_ASSUMPTION_CODES key.
		///		FK_IC_DISCOS_ASSUMPTION_CODES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_assumptionCode">A code indicating the type of assumption resulting in the Disco record; foreign key to ASSUMPTION_CODES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByAssumptionCode(TransactionManager transactionManager, System.String _assumptionCode, int start, int pageLength)
		{
			int count = -1;
			return GetByAssumptionCode(transactionManager, _assumptionCode, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_ASSUMPTION_CODES key.
		///		fkIcDiscosAssumptionCodes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_assumptionCode">A code indicating the type of assumption resulting in the Disco record; foreign key to ASSUMPTION_CODES</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByAssumptionCode(System.String _assumptionCode, int start, int pageLength)
		{
			int count =  -1;
			return GetByAssumptionCode(null, _assumptionCode, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_ASSUMPTION_CODES key.
		///		fkIcDiscosAssumptionCodes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_assumptionCode">A code indicating the type of assumption resulting in the Disco record; foreign key to ASSUMPTION_CODES</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByAssumptionCode(System.String _assumptionCode, int start, int pageLength,out int count)
		{
			return GetByAssumptionCode(null, _assumptionCode, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_ASSUMPTION_CODES key.
		///		FK_IC_DISCOS_ASSUMPTION_CODES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_assumptionCode">A code indicating the type of assumption resulting in the Disco record; foreign key to ASSUMPTION_CODES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public abstract TList<IcDisco> GetByAssumptionCode(TransactionManager transactionManager, System.String _assumptionCode, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_DSCS key.
		///		FK_IC_DISCOS_DSCS Description: 
		/// </summary>
		/// <param name="_dscId">DSC Id of DSC on which disco record sits</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByDscId(System.Int32? _dscId)
		{
			int count = -1;
			return GetByDscId(_dscId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_DSCS key.
		///		FK_IC_DISCOS_DSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscId">DSC Id of DSC on which disco record sits</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		/// <remarks></remarks>
		public TList<IcDisco> GetByDscId(TransactionManager transactionManager, System.Int32? _dscId)
		{
			int count = -1;
			return GetByDscId(transactionManager, _dscId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_DSCS key.
		///		FK_IC_DISCOS_DSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscId">DSC Id of DSC on which disco record sits</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByDscId(TransactionManager transactionManager, System.Int32? _dscId, int start, int pageLength)
		{
			int count = -1;
			return GetByDscId(transactionManager, _dscId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_DSCS key.
		///		fkIcDiscosDscs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_dscId">DSC Id of DSC on which disco record sits</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByDscId(System.Int32? _dscId, int start, int pageLength)
		{
			int count =  -1;
			return GetByDscId(null, _dscId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_DSCS key.
		///		fkIcDiscosDscs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_dscId">DSC Id of DSC on which disco record sits</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByDscId(System.Int32? _dscId, int start, int pageLength,out int count)
		{
			return GetByDscId(null, _dscId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_DSCS key.
		///		FK_IC_DISCOS_DSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscId">DSC Id of DSC on which disco record sits</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public abstract TList<IcDisco> GetByDscId(TransactionManager transactionManager, System.Int32? _dscId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_IMPERVIOUS_TYPES key.
		///		FK_IC_DISCOS_IMPERVIOUS_TYPES Description: 
		/// </summary>
		/// <param name="_iaType">Foreign key to IMPERVIOUS_TYPES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByIaType(System.String _iaType)
		{
			int count = -1;
			return GetByIaType(_iaType, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_IMPERVIOUS_TYPES key.
		///		FK_IC_DISCOS_IMPERVIOUS_TYPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_iaType">Foreign key to IMPERVIOUS_TYPES</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		/// <remarks></remarks>
		public TList<IcDisco> GetByIaType(TransactionManager transactionManager, System.String _iaType)
		{
			int count = -1;
			return GetByIaType(transactionManager, _iaType, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_IMPERVIOUS_TYPES key.
		///		FK_IC_DISCOS_IMPERVIOUS_TYPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_iaType">Foreign key to IMPERVIOUS_TYPES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByIaType(TransactionManager transactionManager, System.String _iaType, int start, int pageLength)
		{
			int count = -1;
			return GetByIaType(transactionManager, _iaType, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_IMPERVIOUS_TYPES key.
		///		fkIcDiscosImperviousTypes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_iaType">Foreign key to IMPERVIOUS_TYPES</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByIaType(System.String _iaType, int start, int pageLength)
		{
			int count =  -1;
			return GetByIaType(null, _iaType, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_IMPERVIOUS_TYPES key.
		///		fkIcDiscosImperviousTypes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_iaType">Foreign key to IMPERVIOUS_TYPES</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public TList<IcDisco> GetByIaType(System.String _iaType, int start, int pageLength,out int count)
		{
			return GetByIaType(null, _iaType, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_IC_DISCOS_IMPERVIOUS_TYPES key.
		///		FK_IC_DISCOS_IMPERVIOUS_TYPES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_iaType">Foreign key to IMPERVIOUS_TYPES</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.IcDisco objects.</returns>
		public abstract TList<IcDisco> GetByIaType(TransactionManager transactionManager, System.String _iaType, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.IcDisco Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.IcDiscoKey key, int start, int pageLength)
		{
			return GetByIcDiscoId(transactionManager, key.IcDiscoId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_IC_DISCOS index.
		/// </summary>
		/// <param name="_icDiscoId">Primary key, IC Disco ID</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.IcDisco"/> class.</returns>
		public BesAsm.MasterData.Entities.IcDisco GetByIcDiscoId(System.Int32 _icDiscoId)
		{
			int count = -1;
			return GetByIcDiscoId(null,_icDiscoId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_IC_DISCOS index.
		/// </summary>
		/// <param name="_icDiscoId">Primary key, IC Disco ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.IcDisco"/> class.</returns>
		public BesAsm.MasterData.Entities.IcDisco GetByIcDiscoId(System.Int32 _icDiscoId, int start, int pageLength)
		{
			int count = -1;
			return GetByIcDiscoId(null, _icDiscoId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_IC_DISCOS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_icDiscoId">Primary key, IC Disco ID</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.IcDisco"/> class.</returns>
		public BesAsm.MasterData.Entities.IcDisco GetByIcDiscoId(TransactionManager transactionManager, System.Int32 _icDiscoId)
		{
			int count = -1;
			return GetByIcDiscoId(transactionManager, _icDiscoId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_IC_DISCOS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_icDiscoId">Primary key, IC Disco ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.IcDisco"/> class.</returns>
		public BesAsm.MasterData.Entities.IcDisco GetByIcDiscoId(TransactionManager transactionManager, System.Int32 _icDiscoId, int start, int pageLength)
		{
			int count = -1;
			return GetByIcDiscoId(transactionManager, _icDiscoId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_IC_DISCOS index.
		/// </summary>
		/// <param name="_icDiscoId">Primary key, IC Disco ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.IcDisco"/> class.</returns>
		public BesAsm.MasterData.Entities.IcDisco GetByIcDiscoId(System.Int32 _icDiscoId, int start, int pageLength, out int count)
		{
			return GetByIcDiscoId(null, _icDiscoId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_IC_DISCOS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_icDiscoId">Primary key, IC Disco ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.IcDisco"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.IcDisco GetByIcDiscoId(TransactionManager transactionManager, System.Int32 _icDiscoId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;IcDisco&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;IcDisco&gt;"/></returns>
		public static TList<IcDisco> Fill(IDataReader reader, TList<IcDisco> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.IcDisco c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("IcDisco")
					.Append("|").Append((System.Int32)reader[((int)IcDiscoColumn.IcDiscoId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<IcDisco>(
					key.ToString(), // EntityTrackingKey
					"IcDisco",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.IcDisco();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.IcDiscoId = (System.Int32)reader[((int)IcDiscoColumn.IcDiscoId - 1)];
					c.OriginalIcDiscoId = c.IcDiscoId;
					c.ParcelId = (reader.IsDBNull(((int)IcDiscoColumn.ParcelId - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.ParcelId - 1)];
					c.DivideId = (reader.IsDBNull(((int)IcDiscoColumn.DivideId - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DivideId - 1)];
					c.DscId = (reader.IsDBNull(((int)IcDiscoColumn.DscId - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DscId - 1)];
					c.IaType = (reader.IsDBNull(((int)IcDiscoColumn.IaType - 1)))?null:(System.String)reader[((int)IcDiscoColumn.IaType - 1)];
					c.AssumptionCode = (reader.IsDBNull(((int)IcDiscoColumn.AssumptionCode - 1)))?null:(System.String)reader[((int)IcDiscoColumn.AssumptionCode - 1)];
					c.TimeFrame = (reader.IsDBNull(((int)IcDiscoColumn.TimeFrame - 1)))?null:(System.String)reader[((int)IcDiscoColumn.TimeFrame - 1)];
					c.IaTimeFrame = (reader.IsDBNull(((int)IcDiscoColumn.IaTimeFrame - 1)))?null:(System.String)reader[((int)IcDiscoColumn.IaTimeFrame - 1)];
					c.DiscoArea = (reader.IsDBNull(((int)IcDiscoColumn.DiscoArea - 1)))?null:(System.Decimal?)reader[((int)IcDiscoColumn.DiscoArea - 1)];
					c.Effectiveness = (reader.IsDBNull(((int)IcDiscoColumn.Effectiveness - 1)))?null:(System.Decimal?)reader[((int)IcDiscoColumn.Effectiveness - 1)];
					c.Comment = (reader.IsDBNull(((int)IcDiscoColumn.Comment - 1)))?null:(System.String)reader[((int)IcDiscoColumn.Comment - 1)];
					c.IsActive = (reader.IsDBNull(((int)IcDiscoColumn.IsActive - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.IsActive - 1)];
					c.EditedBy = (System.String)reader[((int)IcDiscoColumn.EditedBy - 1)];
					c.EditReason = (System.String)reader[((int)IcDiscoColumn.EditReason - 1)];
					c.Status = (System.String)reader[((int)IcDiscoColumn.Status - 1)];
					c.AppendDate = (System.DateTime)reader[((int)IcDiscoColumn.AppendDate - 1)];
					c.EditDate = (reader.IsDBNull(((int)IcDiscoColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)IcDiscoColumn.EditDate - 1)];
					c.ParcelidDeprecated = (reader.IsDBNull(((int)IcDiscoColumn.ParcelidDeprecated - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.ParcelidDeprecated - 1)];
					c.DivideidDeprecated = (reader.IsDBNull(((int)IcDiscoColumn.DivideidDeprecated - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DivideidDeprecated - 1)];
					c.DscidDeprecated = (reader.IsDBNull(((int)IcDiscoColumn.DscidDeprecated - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DscidDeprecated - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.IcDisco"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.IcDisco"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.IcDisco entity)
		{
			if (!reader.Read()) return;
			
			entity.IcDiscoId = (System.Int32)reader[((int)IcDiscoColumn.IcDiscoId - 1)];
			entity.OriginalIcDiscoId = (System.Int32)reader["ic_disco_id"];
			entity.ParcelId = (reader.IsDBNull(((int)IcDiscoColumn.ParcelId - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.ParcelId - 1)];
			entity.DivideId = (reader.IsDBNull(((int)IcDiscoColumn.DivideId - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DivideId - 1)];
			entity.DscId = (reader.IsDBNull(((int)IcDiscoColumn.DscId - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DscId - 1)];
			entity.IaType = (reader.IsDBNull(((int)IcDiscoColumn.IaType - 1)))?null:(System.String)reader[((int)IcDiscoColumn.IaType - 1)];
			entity.AssumptionCode = (reader.IsDBNull(((int)IcDiscoColumn.AssumptionCode - 1)))?null:(System.String)reader[((int)IcDiscoColumn.AssumptionCode - 1)];
			entity.TimeFrame = (reader.IsDBNull(((int)IcDiscoColumn.TimeFrame - 1)))?null:(System.String)reader[((int)IcDiscoColumn.TimeFrame - 1)];
			entity.IaTimeFrame = (reader.IsDBNull(((int)IcDiscoColumn.IaTimeFrame - 1)))?null:(System.String)reader[((int)IcDiscoColumn.IaTimeFrame - 1)];
			entity.DiscoArea = (reader.IsDBNull(((int)IcDiscoColumn.DiscoArea - 1)))?null:(System.Decimal?)reader[((int)IcDiscoColumn.DiscoArea - 1)];
			entity.Effectiveness = (reader.IsDBNull(((int)IcDiscoColumn.Effectiveness - 1)))?null:(System.Decimal?)reader[((int)IcDiscoColumn.Effectiveness - 1)];
			entity.Comment = (reader.IsDBNull(((int)IcDiscoColumn.Comment - 1)))?null:(System.String)reader[((int)IcDiscoColumn.Comment - 1)];
			entity.IsActive = (reader.IsDBNull(((int)IcDiscoColumn.IsActive - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.IsActive - 1)];
			entity.EditedBy = (System.String)reader[((int)IcDiscoColumn.EditedBy - 1)];
			entity.EditReason = (System.String)reader[((int)IcDiscoColumn.EditReason - 1)];
			entity.Status = (System.String)reader[((int)IcDiscoColumn.Status - 1)];
			entity.AppendDate = (System.DateTime)reader[((int)IcDiscoColumn.AppendDate - 1)];
			entity.EditDate = (reader.IsDBNull(((int)IcDiscoColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)IcDiscoColumn.EditDate - 1)];
			entity.ParcelidDeprecated = (reader.IsDBNull(((int)IcDiscoColumn.ParcelidDeprecated - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.ParcelidDeprecated - 1)];
			entity.DivideidDeprecated = (reader.IsDBNull(((int)IcDiscoColumn.DivideidDeprecated - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DivideidDeprecated - 1)];
			entity.DscidDeprecated = (reader.IsDBNull(((int)IcDiscoColumn.DscidDeprecated - 1)))?null:(System.Int32?)reader[((int)IcDiscoColumn.DscidDeprecated - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.IcDisco"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.IcDisco"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.IcDisco entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IcDiscoId = (System.Int32)dataRow["ic_disco_id"];
			entity.OriginalIcDiscoId = (System.Int32)dataRow["ic_disco_id"];
			entity.ParcelId = Convert.IsDBNull(dataRow["parcel_id"]) ? null : (System.Int32?)dataRow["parcel_id"];
			entity.DivideId = Convert.IsDBNull(dataRow["divide_id"]) ? null : (System.Int32?)dataRow["divide_id"];
			entity.DscId = Convert.IsDBNull(dataRow["dsc_id"]) ? null : (System.Int32?)dataRow["dsc_id"];
			entity.IaType = Convert.IsDBNull(dataRow["ia_type"]) ? null : (System.String)dataRow["ia_type"];
			entity.AssumptionCode = Convert.IsDBNull(dataRow["assumption_code"]) ? null : (System.String)dataRow["assumption_code"];
			entity.TimeFrame = Convert.IsDBNull(dataRow["time_frame"]) ? null : (System.String)dataRow["time_frame"];
			entity.IaTimeFrame = Convert.IsDBNull(dataRow["ia_time_frame"]) ? null : (System.String)dataRow["ia_time_frame"];
			entity.DiscoArea = Convert.IsDBNull(dataRow["disco_area"]) ? null : (System.Decimal?)dataRow["disco_area"];
			entity.Effectiveness = Convert.IsDBNull(dataRow["effectiveness"]) ? null : (System.Decimal?)dataRow["effectiveness"];
			entity.Comment = Convert.IsDBNull(dataRow["comment"]) ? null : (System.String)dataRow["comment"];
			entity.IsActive = Convert.IsDBNull(dataRow["is_active"]) ? null : (System.Int32?)dataRow["is_active"];
			entity.EditedBy = (System.String)dataRow["edited_by"];
			entity.EditReason = (System.String)dataRow["edit_reason"];
			entity.Status = (System.String)dataRow["status"];
			entity.AppendDate = (System.DateTime)dataRow["append_date"];
			entity.EditDate = Convert.IsDBNull(dataRow["edit_date"]) ? null : (System.DateTime?)dataRow["edit_date"];
			entity.ParcelidDeprecated = Convert.IsDBNull(dataRow["parcelid_deprecated"]) ? null : (System.Int32?)dataRow["parcelid_deprecated"];
			entity.DivideidDeprecated = Convert.IsDBNull(dataRow["divideid_deprecated"]) ? null : (System.Int32?)dataRow["divideid_deprecated"];
			entity.DscidDeprecated = Convert.IsDBNull(dataRow["dscid_deprecated"]) ? null : (System.Int32?)dataRow["dscid_deprecated"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.IcDisco"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.IcDisco Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.IcDisco entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region AssumptionCodeSource	
			if (CanDeepLoad(entity, "AssumptionCode|AssumptionCodeSource", deepLoadType, innerList) 
				&& entity.AssumptionCodeSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.AssumptionCode ?? string.Empty);
				AssumptionCode tmpEntity = EntityManager.LocateEntity<AssumptionCode>(EntityLocator.ConstructKeyFromPkItems(typeof(AssumptionCode), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.AssumptionCodeSource = tmpEntity;
				else
					entity.AssumptionCodeSource = DataRepository.AssumptionCodeProvider.GetByAssumptionCodeId(transactionManager, (entity.AssumptionCode ?? string.Empty));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'AssumptionCodeSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.AssumptionCodeSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.AssumptionCodeProvider.DeepLoad(transactionManager, entity.AssumptionCodeSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion AssumptionCodeSource

			#region DscIdSource	
			if (CanDeepLoad(entity, "Dsc|DscIdSource", deepLoadType, innerList) 
				&& entity.DscIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.DscId ?? (int)0);
				Dsc tmpEntity = EntityManager.LocateEntity<Dsc>(EntityLocator.ConstructKeyFromPkItems(typeof(Dsc), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.DscIdSource = tmpEntity;
				else
					entity.DscIdSource = DataRepository.DscProvider.GetByDscId(transactionManager, (entity.DscId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DscIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.DscIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.DscProvider.DeepLoad(transactionManager, entity.DscIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion DscIdSource

			#region IaTypeSource	
			if (CanDeepLoad(entity, "ImperviousType|IaTypeSource", deepLoadType, innerList) 
				&& entity.IaTypeSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.IaType ?? string.Empty);
				ImperviousType tmpEntity = EntityManager.LocateEntity<ImperviousType>(EntityLocator.ConstructKeyFromPkItems(typeof(ImperviousType), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IaTypeSource = tmpEntity;
				else
					entity.IaTypeSource = DataRepository.ImperviousTypeProvider.GetByImperviousTypeId(transactionManager, (entity.IaType ?? string.Empty));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IaTypeSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IaTypeSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.ImperviousTypeProvider.DeepLoad(transactionManager, entity.IaTypeSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IaTypeSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.IcDisco object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.IcDisco instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.IcDisco Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.IcDisco entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region AssumptionCodeSource
			if (CanDeepSave(entity, "AssumptionCode|AssumptionCodeSource", deepSaveType, innerList) 
				&& entity.AssumptionCodeSource != null)
			{
				DataRepository.AssumptionCodeProvider.Save(transactionManager, entity.AssumptionCodeSource);
				entity.AssumptionCode = entity.AssumptionCodeSource.AssumptionCodeId;
			}
			#endregion 
			
			#region DscIdSource
			if (CanDeepSave(entity, "Dsc|DscIdSource", deepSaveType, innerList) 
				&& entity.DscIdSource != null)
			{
				DataRepository.DscProvider.Save(transactionManager, entity.DscIdSource);
				entity.DscId = entity.DscIdSource.DscId;
			}
			#endregion 
			
			#region IaTypeSource
			if (CanDeepSave(entity, "ImperviousType|IaTypeSource", deepSaveType, innerList) 
				&& entity.IaTypeSource != null)
			{
				DataRepository.ImperviousTypeProvider.Save(transactionManager, entity.IaTypeSource);
				entity.IaType = entity.IaTypeSource.ImperviousTypeId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region IcDiscoChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.IcDisco</c>
	///</summary>
	public enum IcDiscoChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>AssumptionCode</c> at AssumptionCodeSource
		///</summary>
		[ChildEntityType(typeof(AssumptionCode))]
		AssumptionCode,
			
		///<summary>
		/// Composite Property for <c>Dsc</c> at DscIdSource
		///</summary>
		[ChildEntityType(typeof(Dsc))]
		Dsc,
			
		///<summary>
		/// Composite Property for <c>ImperviousType</c> at IaTypeSource
		///</summary>
		[ChildEntityType(typeof(ImperviousType))]
		ImperviousType,
		}
	
	#endregion IcDiscoChildEntityTypes
	
	#region IcDiscoFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;IcDiscoColumn&gt;"/> class
	/// that is used exclusively with a <see cref="IcDisco"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class IcDiscoFilterBuilder : SqlFilterBuilder<IcDiscoColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the IcDiscoFilterBuilder class.
		/// </summary>
		public IcDiscoFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the IcDiscoFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public IcDiscoFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the IcDiscoFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public IcDiscoFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion IcDiscoFilterBuilder
	
	#region IcDiscoParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;IcDiscoColumn&gt;"/> class
	/// that is used exclusively with a <see cref="IcDisco"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class IcDiscoParameterBuilder : ParameterizedSqlFilterBuilder<IcDiscoColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the IcDiscoParameterBuilder class.
		/// </summary>
		public IcDiscoParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the IcDiscoParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public IcDiscoParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the IcDiscoParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public IcDiscoParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion IcDiscoParameterBuilder
	
	#region IcDiscoSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;IcDiscoColumn&gt;"/> class
	/// that is used exclusively with a <see cref="IcDisco"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class IcDiscoSortBuilder : SqlSortBuilder<IcDiscoColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the IcDiscoSqlSortBuilder class.
		/// </summary>
		public IcDiscoSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion IcDiscoSortBuilder
	
} // end namespace
